<template>
  <div>
    <div id="slider" class="mui-slider">
      <div
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a class="mui-control-item mui-active" @click="getMsg(0)">推荐</a>
          <a
            class="mui-control-item"
            v-for="val in title"
            :key="val.id"
            @click="getMsg(val.id)"
          >{{val.title}}</a>
        </div>
      </div>
    </div>
    <ul>
      <router-link :to="'/imgs'+val.id" tag="li" v-for="val in getMag" :key="val.id">
        <img v-lazy="val.img_url">
      </router-link>
    </ul>
  </div>
</template>
<script>
import mui from "../../../../node_modules/mui/js/mui";

export default {
  data() {
    return {
      title: [],
      getMag: []
    };
  },
  created() {
    this.getHder();
    this.getMsg(0);
  },
  methods: {
    getHder() {
      this.$http.get("api/getimgcategory").then(res => {
        this.title = res.body.message;
      });
    },
    getMsg(id) {
      this.$http.get("api/getimages/" + id).then(res => {
        this.getMag = res.body.message;
      });
    }
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  }
};
</script>
<style scoped>
img {
  width: 100%;
}
img[lazy="loading"] {
  width: 40px;
  height: 300px;
  margin: auto;
}
</style>

